<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" />
    <title>首页 </title>
    <link rel="icon" href="favicon.ico" type="image/ico">
    <link href="css/bootstrap.min.css" th:href="@{/css/bootstrap.min.css}" rel="stylesheet">
    <link href="css/materialdesignicons.min.css"  th:href="@{/css/materialdesignicons.min.css}" rel="stylesheet">
    <link href="css/style.min.css" th:href="@{/css/style.min.css}" rel="stylesheet"></head>

<body>
<div class="lyear-layout-web" id="mainContent">
    <div  th:if="${session.grade} eq 3">
        <div th:replace="~{main::rightbar}"></div>
    </div>
    <div  th:if="${session.grade} eq 1">
        <div th:replace="~{kfmain::kfrightbar}"></div>
    </div>
    <div  th:if="${session.grade} eq 2">
        <div th:replace="~{csmain::csrightbar}"></div>
    </div>
    <div th:replace="~{main::topbar}"></div>
    <div class="lyear-layout-container">

        <header class="lyear-layout-header" th:fragment="topbar">

            <nav class="navbar navbar-default">
                <div class="topbar">

                    <div class="topbar-left">
                        <div class="lyear-aside-toggler">
                            <span class="lyear-toggler-bar"></span>
                            <span class="lyear-toggler-bar"></span>
                            <span class="lyear-toggler-bar"></span>
                        </div>
                        <span class="navbar-page-title"> 文件管理 </span>
                    </div>
                    <div th:replace="~{main::bar}"></div>


                </div>
            </nav>

        </header>

        <main class="lyear-layout-content">


            <div class="container-fluid">



                <div class="row">

                    <div class="col-lg-12">
                        <div class="card">
                            <div class="card-header">
                                <h4>文件列表</h4>
                            </div>
                            <div class="card-body">

                                <table>
                                    <form onsubmit="return false" id="formAddtr" method="get">
                                        <td>
                                            <select data-placeholder="请选择实验室"  id="filepath" name="filepath"  class="form-control chosen-select" style="width: 100%; "  required >
                                                <option value="0">选择文件夹</option>
                                                <!--playerRoleList后台获取到的集合th:each进行遍历,playerRole作为集合对象的变量名称,th:value="${playerRole.id}作为value值				                        th:text="${playerRole.name}"作为需要显示的内容-->				                        <option th:each="role:${roleList}" th:value="${role.id}"				                                th:text="${role.role_desc}"></option>
                                                <option th:each="role:${filepath}" th:value="${role.id}"

                                                        th:text="${role.name}"></option>
                                            </select>
                                        </td>
                                        <td>&nbsp;&nbsp;</td>
                                        <td>
                                            <button class="btn btn-primary m-r-5" onclick="subForm()"><i class="mdi mdi-plus"></i>搜索</button>
                                        </td>
                                        <td>&nbsp;&nbsp;</td>
                                        <td>

                                            <button class="btn btn-primary m-r-5" onclick="addfilepath()"><i class="mdi mdi-plus"></i> 新增文件夹</button>


                                        </td>
                                    </form>
                                </table>

                                <div class="table-responsive">
                                    <table class="table table-hover" >
                                        <thead>
                                        <tr>
                                            <th>文件名称</th>
                                            <th>上传者姓名</th>
                                            <th>创建时间</th>
                                            <th>版本号</th>
                                            <th>下载</th>
                                            <th>查看日志</th>
                                        </tr>
                                        </thead>
                                        <tbody id="boby">

                                        <!--<tr>
                                            <td>8</td>
                                            <td>Logo设计</td>
                                            <td>10/02/2019</td>
                                            <td>01/03/2019</td>
                                            <td><span class="label label-warning">完成</span></td>
                                            <td>
                                                <div class="progress progress-striped progress-sm">
                                                    <div class="progress-bar progress-bar-success" style="width: 100%;"></div>
                                                </div>
                                            </td>
                                        </tr>-->
                                        </tbody>
                                    </table>
                                </div>
                            </div>
                        </div>
                    </div>

                </div>

            </div>

        </main>
        <!--End 页面主要内容-->
    </div>
</div>

<script type="text/javascript" src="js/jquery.min.js"></script>
<script type="text/javascript" src="js/bootstrap.min.js"></script>
<script type="text/javascript" src="js/perfect-scrollbar.min.js"></script>
<script type="text/javascript" src="js/main.min.js"></script>

<!--图表插件-->
<script type="text/javascript" src="js/Chart.js"></script>

<script type="text/javascript">
    //别忘了导入该用的js文件
    function addfilepath() {
        var why;
        why=prompt("输入文件夹名称?");
        var data1={"why":why};

        console.log(data1);
        $.ajax({
            type:'post',
            url:'/addfilepath',
            contentType: "application/json",
            datatype:"JSON",
            // data:user,
            //contentType:'application/json;charset=UTF-8',
            data:JSON.stringify(data1),
            async : true,
            // global:false,
            success:function(json){
                alert('操作成功');
                subForm();

            },
            error: function (data) {
                alert('操作失败');
            },
        });}

    function subForm() {
        var checkValue=$("#filepath").val();
        console.log(checkValue)
        $.ajax({

            url: '/filelist/'+checkValue, //请求的url
            type: 'get', //请求的方式
            //form表单里要提交的内容，里面的input等写上name就会提交，这是序列化
            cache : false,
            async : true,
            error:function (data) {
                alert('请求失败');
            },
            success:function (data) {
                console.log(data)
                var str1 = "";
                //清空table中的html
                $("#boby").html("");
                for(var i = 0;i<data.length;i++){
                    str1 = "<tr>" +
                        "<td>"+data[i].name + "</td>" +
                        "<td>"+data[i].upname + "</td>" +
                        "<td>"+data[i].up + "</td>" +
                        "<td>"+data[i].edition+ "</td>" +
                        "<td>"+"<a href='/down2/"+data[i].id+"'"+"style=' height: 21px;\n" +
                        "            line-height: 21px;\n" +
                        "            padding: 0 11px;\n" +
                        "            background-color: #33cabb;\n" +
                        "           border-color: #33cabb;\n" +
                        "            color: #fff!important;\n" +
                        "            border-radius: 3px;\n" +
                        "            display: inline-block;\n" +
                        "            text-decoration: none;\n" +
                        "            font-size: 12px;\n" +
                        "            outline: none;'>下载</a>"+"</td>" +
                        "<td>"+"<a href='/rizhi?name="+data[i].id+"&filepath="+data[i].filepath+"'"+"style=' height: 21px;\n" +
                        "            line-height: 21px;\n" +
                        "            padding: 0 11px;\n" +
                        "            background-color: #33cabb;\n" +
                        "           border-color: #33cabb;\n" +
                        "            color: #fff!important;\n" +
                        "            border-radius: 3px;\n" +
                        "            display: inline-block;\n" +
                        "            text-decoration: none;\n" +
                        "            font-size: 12px;\n" +
                        "            outline: none;'>查看日志</a>"+"</td>" +

                        "</tr>";
                    $("#boby").append(str1);
                }
            }
        });
    }
    function deleteuser(id){

        $.ajax({
            type:'delete',
            url:'/user/'+id,
            // data:user,
            //contentType:'application/json;charset=UTF-8',

            async : true,
            // global:false,
            success:function(json){
                alert('删除成功');
                subForm();
            },
            error: function (data) {
                alert('删除失败');
            },
        });


    }

</script>
</body>

</html>